<?php
$v_page = $_SESSION['v_session_page'];
$v_limit_row = $_SESSION['v_session_limit_num_page'];
$v_current_status = ($arr_single_record['C_CURRENT_STATUS']);
$v_detail_status = intval($arr_single_record['C_DETAIL_STATUS']);
// Luu ten style hien thoi
$v_current_style_name = "odd_row";
// Luu ten style tiep theo
$v_next_style_name = "";
$v_staff_id = _get_item_attr_by_id ($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'id');
$v_recordtype_filter = $_SESSION['onegate_current_recordtype'];
for($i=0;$i<sizeof($arr_all_recordtype);$i++){
	if ($arr_all_recordtype[$i]['C_NAME'] == $v_recordtype_filter){
		$v_recordtype_id = $arr_all_recordtype[$i]['PK_RECORDTYPE'];
	}
}

//Kiem tra NSD hien thoi dong vai tro la can bo tiep nhan doi voi loai ho so tuong ung va trang thai cua ho so la "DANG_THU_LY" va C_DETAIL_STATUS <>20
if ((onegate_is_receiver_for_recordtype($v_staff_id,$v_recordtype_id,$_SESSION["recordtype"])) && $v_current_status == "DANG_THU_LY" && $v_detail_status <> 20 ){
	$v_is_receiver_for_recordtype_and_status = 1;
}else{
	$v_is_receiver_for_recordtype_and_status = 0;
}
//Kiem tra NSD hien thoi dong vai tro la lanh dao phu trach duyet ho so lan thu nhat khong?
if ((onegate_is_handler_leader_first_time_for_recordtype($v_staff_id,$v_recordtype_id,$_SESSION["recordtype"])) && $v_current_status == "TRINH_KY" && $v_detail_status == 23 ){
	$v_is_handler_leader_first_time_for_recordtype_and_status = 1;
}else{
	$v_is_handler_leader_first_time_for_recordtype_and_status = 0;
}
//Kiem tra NSD hien thoi dong vai tro la lanh dao phu trach thu ly ho so doi voi loai ho so tuong ung va trang thai cua ho so la "TRINH_KY" va C_DETAIL_STATUS ==30
if ((onegate_is_handler_leader_for_recordtype($v_staff_id,$v_recordtype_id,$_SESSION["recordtype"])) && $v_current_status == "TRINH_KY" && $v_detail_status == 30 ){
	$v_is_handler_leader_for_recordtype_and_status = 1;
}else{
	$v_is_handler_leader_for_recordtype_and_status = 0;
}
//Kiem tra NSD hien thoi dong vai tro la lanh dao phu trach phe duyet ho so doi voi loai ho so tuong ung va trang thai cua ho so la "TRINH_KY" va C_DETAIL_STATUS ==40
if ((onegate_is_approve_leader_for_recordtype($v_staff_id,$v_recordtype_id,$_SESSION["recordtype"])) && $v_current_status == "TRINH_KY" && $v_detail_status == 40 ){
	$v_is_approve_leader_for_recordtype_and_status = 1;
}else{
	$v_is_approve_leader_for_recordtype_and_status = 0;
}
//Kiem tra NSD hien thoi dong vai tro la thu ly chinh hoac nguoi phoi hop thu ly doi voi ho so hien thoi va trang thai cua ho so la "DANG_THU_LY" va C_DETAIL_STATUS <>20
if ( ((onegate_is_main_handler_for_record($v_staff_id,$v_record_id))|| (onegate_is_co_handler_for_record($v_staff_id,$v_record_id)) )&&  $v_current_status == "DANG_THU_LY" && $v_detail_status <> 20){
	$v_is_main_or_co_handler_for_record_and_status = 1;
}else{
	$v_is_main_or_co_handler_for_record_and_status = 0;
}
// Nhung ho so trinh lanh dao sau do lanh dao xem xet roi cap nhat option "Chuyen co quan co tham quyen giai quyet" thi truong hop sau
// se xay ra
$v_permisstion_update_idea = 0;
if(
		onegate_is_main_handler_for_record($v_staff_id,$v_record_id)
		&& ($v_detail_status = 70)
   ){
   		$v_permisstion_update_idea = 1;
   }
# echo 'v_permisstion_update_idea' . $v_permisstion_update_idea;
?>
<!--bang chua tieu de cua form-->
<table width="100%" cellpadding="0" cellspacing="0">
	<tr class="normal_title">
		<td>
			<?php echo CONST_IDEA_VIEW_TITLE; ?>
			<a id="goto" href="" style=".color:white">#</a>
		</td>
	</tr>
</table>
<!-- bang chua cac tieu thuc loc-->
<table class="form_table1" cellpadding="0" cellspacing="0" width="100%" >								
	<tr>
	 	<form action="index.php" name="frm_dsp_all_idea" method="post">
		<input type="hidden" name="hdn_idea_id"  value="<?php echo $v_idea_id; ?>">
		<input type="hidden" name="hdn_record_id"  value="<?php echo $v_record_id; ?>">
		<input type="hidden" name="hdn_recordtype_filter" value="<?php echo $v_recordtype_filter; ?>">
		<input type="hidden" name="fuseaction"  value="">
		<input type="hidden" name="hdn_list_id"  value="">
		<input type='hidden' name='hdn_page' value='<?php echo $v_page;?>'>
		<input type='hidden' name='hdn_record_number_page' value='<?php echo $v_limit_row;?>'>
	</tr>
	<tr>
		<td colspan="10" ><?php echo onegate_show_record_general_info($arr_single_record,$_SESSION['recordtype'],true,$p_petition_link,$p_rate_of_progress_link,$p_document_link,$p_idea_link,$p_notify_link,$p_sign_link,$p_approve_link,$p_licensing_link,$v_url_view_update_record_status); ?></td>
	</tr>
	<tr>
		<td>	
		<table class="list_table2" width="100%" cellpadding="0" cellspacing="0">
			<col width="5%"><col width="25%"><col width="30%"><col width="40%">
			<tr class="header">
				<td><?php echo CONST_ORDER_LABEL; ?></td>
				<td><?php echo CONST_NAME_LABEL; ?></td>
				<td><?php echo CONST_IDEA_DATE_LABEL; ?></td>
				<td><?php echo CONST_CONTENT_LABEL; ?></td>
			</tr>
		</table>	
		<div style="overflow: auto; width: 100%; height:<?php echo _CONST_HEIGHT_OF_LIST?>;padding-left:0px;margin:0px">
		<table class="list_table2" width="100%" cellpadding="0" cellspacing="0">
			<col width="5%"><col width="25%"><col width="30%"><col width="40%">
			<?php 
			if ($v_count_idea>0){
				for($row_index = 0;$row_index< $v_count_idea;$row_index++){
					$v_idea_id = $arr_all_idea[$row_index]['0'];
					$v_suggester_id = $arr_all_idea[$row_index]['1'];
					$v_date = _yyyymmdd_to_ddmmyyyyhhmmss($arr_all_idea[$row_index]['2']);			
					//$v_content = substr(_replace_bad_char($arr_all_idea[$row_index]['3']),0,50);
					$v_content = _replace_bad_char($arr_all_idea[$row_index]['3']);
					$v_file_name = $arr_all_idea[$row_index]['4'];
					$v_suggester_name =_get_item_attr_by_id($_SESSION['arr_all_staff'],$v_suggester_id ,'name');
					
					$v_file_url = trim(CONST_URL_PATH_FROM_ROOT) . $v_file_name;
					$v_file_url = "javascript:filename_onclick('T_ONEGATE_IDEA', 'PK_IDEA', 'C_FILE_NAME', 'C_FILE_CONTENT'," . strval($v_idea_id) . ",'" . $v_file_url ."');" ;
					$v_url = "row_onclick(" . "document.forms(0).hdn_idea_id"  .  "," . $v_idea_id . "," . "'DISPLAY_SINGLE_IDEA','" . $v_goto_url . "')";			
					
					if ($v_current_style_name == "odd_row"){
						$v_current_style_name = "round_row";
					}else{
						$v_current_style_name = "odd_row";
					}?>	
					<tr class="<?php echo $v_current_style_name ?>"> 
						<td align="center">
							<input type="checkbox" name="chk_idea_id" value="<?php echo $v_idea_id; ?>">
						</td>
						<td align="left" onClick="<?php echo $v_url;?>">
							<a name="<?php echo $v_idea_id;?>"><?php echo $v_suggester_name;?></a>
						</td>	
						<td align="center" onclick="<?php echo $v_url ;?>">
							<a name="<?php echo $v_idea_id;?>"><?php echo $v_date; ?></a>
						</td>
						<td align="left" onClick="<?php echo $v_url;?>">
							<a name="<?php echo $v_idea_id;?>"><?php echo $v_content."<br>";?></a>
							<a href="<? echo $v_file_url; ?>" class="normal_link"><? echo $v_file_name;?></a>
						</td>	
					</tr><?php 
				}	
			}
			if ($v_current_style_name == "odd_row"){
				$v_next_style_name = "round_row";
			}else{
				$v_next_style_name = "odd_row";
			}
			echo _add_empty_row($v_count_idea,_CONST_NUMBER_OF_ROW_PER_LIST,$v_current_style_name,$v_next_style_name,4);
			?>
		</table>
		</div>
		</td>
	</tr><!--
	<tr>
		<td align="left" class="small_label">
	  		<small class="small_starmark"><?php echo CONST_RECORD_LIST_HAS_LABEL . $v_count_idea .  CONST_IDEA_LABEL;?></small>
	  	</td>
	</tr>-->
</table>
<table width="100%" border="0">
	<col width="40%"><col width="60%">
	<tr><td height="5"></td></tr>
	<tr align="center">
		<td><?php
		if (($v_is_granted_update) 
			|| ($v_is_receiver_for_recordtype_and_status > 0) 
			|| ($v_is_handler_leader_for_recordtype_and_status > 0) 
			|| ($v_is_approve_leader_for_recordtype_and_status > 0) 
			|| ($v_is_main_or_co_handler_for_record_and_status > 0) 
			|| ($v_is_handler_leader_first_time_for_recordtype_and_status > 0) 
			|| ($v_permisstion_update_idea > 0)
			//Kiem tra NSD hien thoi co quyen duoc cap nhat tien do cong viec khong?
			|| (onegate_is_permission_update_rate_of_progress_for_recordtype($v_staff_id,0,$_SESSION["recordtype"]))			
			
		){ ?>
			<input type="button" value="<?php echo CONST_ADD_IDEA_BUTTON; ?>" name="btn_add" class="normal_button" onClick="btn_add_onclick(document.forms(0).hdn_idea_id, 'DISPLAY_SINGLE_IDEA')">
			<input type="button" value="<?php echo _CONST_DELETE_BUTTON; ?>" name="btn_delete" class="normal_button" onClick="btn_delete_onclick(document.frm_dsp_all_idea.chk_idea_id,document.frm_dsp_all_idea.hdn_list_id,'DELETE_IDEA')"><?php
		}?>
		</td>
	</tr>
</table>
</form>
